-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed homework #2
base: master
Are you sure you want to change the base?
Conversation
const presidentialParties = presidents.map(presidentObj => presidentObj.party) | ||
console.log(presidentialParties) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Get a list of presidents whos first name is James | ||
const presidentsNamedJames = presidents.filter(presidentObj => { | ||
// presidentObj.president.split(' ') is the president name split into an array | ||
// first name is stored at [0] index | ||
return presidentObj.president.split(' ')[0] === 'James' | ||
}) | ||
|
||
console.log(presidentsNamedJames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// find the first president that was a member of the party named Whig | ||
const firstWhigPresident = presidents.find(selectedPresidentObj => selectedPresidentObj.party === 'Whig') | ||
// print to console | ||
console.log(firstWhigPresident.president) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const presidentsBetween1850and1900 = presidents.filter(presidentObj => { | ||
// presidentObj.took_office.split('-')[0] = year the president took office | ||
return (presidentObj.took_office.split('-')[0] > 1850) & (presidentObj.took_office.split('-')[0] < 1900) | ||
}) | ||
|
||
// print to console | ||
console.log(presidentsBetween1850and1900) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const livingPresidents = presidents.filter(presidentObj => presidentObj.death_year === null) | ||
|
||
// print to console | ||
console.log(livingPresidents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const shortTermPresidents = presidents.filter(presidentObj => { | ||
if (presidentObj.left_office === null) { | ||
// if the president never left office, calculate based off the cufrent year (2019) | ||
return (2019 - presidentObj.took_office.split('-')[0]) < 4 | ||
} else { | ||
// below line calculates the year the president took office minus | ||
// the year the president left office and retuns the object if the Result | ||
// is less than 4 | ||
return (presidentObj.left_office.split('-')[0] - presidentObj.took_office.split('-')[0]) < 4 | ||
} | ||
}) | ||
|
||
// print to console | ||
console.log(shortTermPresidents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay